package wmh.day01092.dao.Impl;

import wmh.day01092.dao.Scenic_SpotDao;
import wmh.day01092.po.Scenic_Spot;
import wmh.day01092.utils.BaseDao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

    public class Scenic_SpotDaoImpl extends BaseDao implements Scenic_SpotDao {
        @Override
        public List<Scenic_Spot> getAllScenic_Spot() {
            //1.创建Scenic_Spot集合对象，用来存储数据库查询返回的结果集数据
            List<Scenic_Spot> scenic_spots = new ArrayList<>();
            //2.创建Scenic_Spot对象，用来存储单条数据
            Scenic_Spot scenic_spot = null;
            //3.定义查询Scenic_Spot表所有数据的sql语句
            String sql = "SELECT * FROM Scenic_Spot";
            //4.调用公共的查询rs结果集方法
            super.rs = super.executeQuery(sql);
            //5.循环遍历rs结果集
            try {
                while (rs.next()) {
                    //实例化tripmode对象
                    scenic_spot = new Scenic_Spot();
                    scenic_spot.setSS_ID(rs.getInt("SS_ID"));
                    scenic_spot.setSS_NAME(rs.getString("SS_NAME"));
                    scenic_spot.setSS_DURATION(rs.getString("SS_DURATION"));
                    scenic_spot.setSS_CONTENT(rs.getString("SS_CONTENT"));
                    //将赋值后的单条对象存储到Scenic_Spots集合对象中
                    scenic_spots.add(scenic_spot);
                }
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                //6.释放所有资源
                super.closeAll(rs, pstmt, conn);
                // super.closeAllConn(rs.pstmt, conn);
            }
            return scenic_spots;
        }

    }